﻿#include "SkyBoxComponent.h"
#include "Asset/EngineDefaultPackage.h"
#include "Scene/Scene.h"

void RSkyBoxComponent::SetTexture(RTextureCubePtr InTexture)
{
    Texture=InTexture;

    Material=NewObject<RMaterial>();
    Material->CopyFrom(REngineDefaultPackage::Get()->GetDefaultSkyBoxMaterial());
    
    //由于天空盒材质只用了一个纹理，所以只设置第一个纹理
    Material->SetTextureCubeByIndex(0,Texture);
}

void RSkyBoxComponent::Paint(CRenderScene* InRenderData)
{
    Super::Paint(InRenderData);

    SRenderMeshInstanceData& MeshInstanceData=InRenderData->MeshInstances.Emplace();
    MeshInstanceData.Position=GetNode()->GetWorldPosition();
    MeshInstanceData.Rotation=GetNode()->GetWorldRotation();
    MeshInstanceData.Scale=GetNode()->GetScale()* 1000.0f;

    MeshInstanceData.BoundingSphereRadius=MeshInstanceData.Scale.GetMax();
    MeshInstanceData.CastShadow=false;

    MeshInstanceData.MeshSections=REngineDefaultPackage::Get()->GetSphereMesh()->GetRenderMeshes();
    MeshInstanceData.Materials.Add(Material->GetRenderMaterial());
    

}

void RSkyBoxComponent::FirstTimeInitializeObject()
{
    Material=REngineDefaultPackage::Get()->GetDefaultSkyBoxMaterial();
}
